import Vue from 'vue'
import Router from 'vue-router'
import Login from'@/components/Login'
import home from '@/components/Home'
import welcome from '@/components/Welcome'
// import userList from '@/components/admin/UserList.vue'
import userList from '@/components/admin/UserList.vue'
Vue.use(Router)

const router= new Router({
  mode:'history',
  routes: [
    {
      path: '/',
      redirect:'login'
    },
    {
      path:'/login',
      name:'Login',
      component:Login
    },
    {
      path:'/home',
      name:'home',
      component:home,
      redirect:'/welcome',
      children:[
        {
          path:'/welcome',
          name:'welcome',
          component:welcome
        },
        {
          path:'/user',
          name:'userList',
          component:userList
        }
      ]
    }
  ]
})
router.beforeEach((to,from,next)=>{
  if(to.path=='/login')
  return next();
  const userFlag=window.sessionStorage.getItem("user")
  if(!userFlag){
    return next('/login')
  }
  next()
})
export default router
